On this page

Skip to content

Reasons Why ASPNETCORE_ENVIRONMENT Fails to Take Effect

I've been a bit lazy with writing notes lately, so I'll just keep this one brief.

I previously wrote an article titled "A Brief Discussion on Environment Name Settings and Applications in ASP.NET Core", but I recently encountered a project that required setting the environment via Windows environment variables, so I referred to the Microsoft article "Use multiple environments in ASP.NET Core - Set environment variable globally".

After configuring it, I found that the project was still only reading appsettings.json and not appsettings.{Environment}.json. Neither restarting the website nor restarting the application pool had any effect. Since this was a client's environment and I wasn't familiar with it, I didn't resort to the "restart everything to fix everything" approach immediately.

Later, I found this article: "Methods for Setting Environment Variables in IIS-deployed .NET Core", and realized that IIS needs to be restarted for the environment variable settings to take effect. The issue was resolved after executing the following command:

bash
iisreset /restart

TIP

You may need administrator privileges to execute the command above.

Change Log

  • 2024-09-19 Initial version created.